<?PHP
// PHP World of Warcraft teleporting script
// Created by Gachl (Daniel Vogel)
//Modified For ReVer Project by Panicc.co

include_once "configa.php";

// Change following:
$config = "scripts.inc.php"; 
$costs = 0; 
$usingtype = "n"; 
$configfilename = "config_teleport.cfg"; 

// ########################
// #Don't change from here#
// ########################
require_once($config);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title><?= $websitetitle ?></title>
</head>
<body>
  <?PHP
// Script
$wuser = fGetUser($userid);
if ($wuser === false)
  die("The user with the user id " . $userid . " does not exists!" . ($userid == 0 ? " Website admin please set up the current user id settings!" : ''));

// Load config file
// This code is stupid <.<
if ($usingtype != "n") {
	$conffile = "";
	do {
		if (!file_exists($configfilename)) {
			if (!is_writable(dirname($configfilename))) {
				die("Please create a file with the name &quot;$configfilename&quot; and make it writable (chmod 777).");
			}
			$fh = fopen($configfilename, 'w');
			fwrite($fh, $usingtype . "\n");
			fclose($fh);
		}
		$fh = fopen($configfilename, "r");
		while (!feof($fh))
			$conffile = fread($fh, 1024);
		fclose($fh);
		if (trim($conffile) != "") {
			$conffile = split("\n", $conffile);
			$config['usingtype'] = $conffile[0];
		} else {
			$config['usingtype'] = "n";
		}
		if ($config['usingtype'] != $usingtype) {
			$fh = fopen($configfilename, "w");
			fwrite($fh, $usingtype);
			fclose($fh);
		}
	} while ($config['usingtype'] != $usingtype);
	unset($conffile[0]);
	foreach ($conffile as $confline) {
		$confline = split(";", $confline);
		$config[$confline[0]] = $confline[1];
	}

	if ($usingtype == "e") {
		$now = time();
		$sub = (intval($now) - (intval($config[1]) + ($usingspan * 60)));
		if (!empty($config[1]) && ($sub < 0))
			die("This tool cannot be used at the moment. You have to wait " . round($sub * (-1) / 60, 1) . " minute(s).");
	}
	if ($usingtype == "a") {
		$now = time();
		$sub = (intval($now) - (intval($config[$userid]) + ($usingspan * 60)));
		if (!empty($config[$userid]) && ($sub < 0))
			die("You can't use this tool. You have to wait " . round($sub * (-1) / 60, 1) . " minute(s).");
	}
}

if (!empty($_POST['cid']) && !empty($_POST['tid'])) {
	// Do porting here
	
	$charid = intval($_POST['cid']);
	if ($usingtype == "c") {
		$now = time();
		$sub = (intval($now) - (intval($config[$charid]) + ($usingspan * 60)));
		if (!empty($config[$charid]) && ($sub < 0))
			die("You can't use this tool with this character. You have to wait " . round($sub * (-1) / 60, 1) . " minute(s).");
	}
	$res = fMySQL_query('SELECT * FROM `characters` WHERE `guid` = '.$charid.';', DB_ACCOUNT);
	if (!($res = mysql_fetch_assoc($res))) {
		die('This character does not exists.');
	}
	if ($res['acct'] != $wuser['acct']) {
		die('This character is not yours!');
	}
	if (itnval($res['gold']) < $costs) {
		die('You have not enough gold.');
	}
	$newgold = $res['gold'] - $costs;
	if ($res['online'] != "0") {
		die('You are currently logged in with that character. Please log out before you port!');
	}

	if (!isset($_POST['tid'])) {
		die('No target place selected.');
	}
	$tid = intval($_POST['tid']);
	$res = fMySQL_query('SELECT * FROM `recall` WHERE `id` = '.$tid.';', DB_WORLD);
	if (!($res = mysql_fetch_assoc($res))) {
		die('This target place does not exists.');
	}
	// everything is ok here so we can port.
	mysql_select_db('antrix_account');
	fMySQL_query('UPDATE `characters` SET `gold` = \''.$newgold.'\' WHERE `guid` = '.$charid.';', DB_ACCOUNT);
	fMySQL_query('UPDATE `characters` SET `positionX` = \''.$res['positionX'].'\', `positionY` = \''.$res['positionY'].'\', `positionZ` = \''.$res['positionZ'].'\', `orientation` = \'0\', `mapId` = \''.$res['MapId'].'\', `zoneId` = \'1\' WHERE `guid` = '.$charid.';', DB_ACCOUNT);
	// Save config file
		if ($usingtype != "n") {
			$fh = fopen($configfilename, "w");
			fwrite($fh, $usingtype . "\n");
			switch ($usingtype) {
			case "a":
				$config[$userid] = time();
				break;
			case "c":
				$config[$charid] = time();
				break;
			case "e":
				$config[1] = time();
				break;
			}
			foreach ($config as $id => $time) {
				if (($id != "usingtype") && !empty($id)) {
					fwrite($fh, $id . ";" . $time . "\n");
				}
			}
			fclose($fh);
		}
	echo "Your character has been teleported.";
}
?>
<form action="?" method="POST">
	<table>
		<tr>
			<td>Character:&nbsp;</td><td><select name="cid">
<?PHP
$res = fMySQL_query('SELECT * FROM `characters` WHERE `acct` = ' . $wuser['acct'] . ';', DB_ACCOUNT);
while ($row = mysql_fetch_assoc($res))
	echo '<option value="'.$row['guid'].'">'.$row['name'].'</option>'."\n";
?>
				</select>
			</td>
		</tr>
		<tr>
			<td>Target place:&nbsp;</td><td><select name="tid">
<?PHP 
$res = fMySQL_query('SELECT * FROM `recall`;', DB_WORLD);
while ($row = mysql_fetch_assoc($res))
	echo '<option value="'.$row['id'].'">'.$row['name'].'</option>'."\n";
?>
				</select>
			</td>
		<tr>
			<td></td><td><input type="submit" value="Teleport"></td>
		</tr>
	</table>
</form>
You have to be logged out with you character. Teleporting costs you <?PHP $ch = intval(substr($costs, -2));
$si = intval(substr(round(intval($costs) / 100), -2));
$go = intval(round(intval($costs) / 10000)); echo "$go Gold, $si Silver and $ch copper"; ?>.
</body>
</html>
<!-- This script is written by Gachl (Daniel Vogel). http://codefreak.net http://data-universal.net http://blog.codefreak.net Queries: <?= $qcount ?> -->